<?php
    $auth = Yii::app()->authManager;
    $roles = Yii::app()->authManager->getRoles();
?>

<div id="userAssignments">
    <div class="assignments span-15 first grid-view">
        <h3><a href="<?php echo $this->createUrl('assignment/index');?>">Back to list</a></h3>
        <?php echo CHtml::beginForm(array('assignment/assign', 'userId'=>$model->getId()), 'post');?>
        <table>
            <caption style="font-weight:bold"><?php echo 'Role assignment for '.$model->username;?></caption>
            <thead>
                <tr>
                    <td>Name</td>
                    <td>Desription</td>
                    <td>Assignment</td>
                </tr>
            </thead>
            <tbody>
                <?php foreach($roles as $role):?>
                <?php $role->attachBehavior('authItem', new AuthItemBehavior);?>
                <tr>
                    <td><?php echo $role->getUpdateNameLink();?></td>
                    <td><?php echo $role->getDescription();?></td>
                    <td><?php echo CHtml::checkBox('Assign['.$role->getName().']', $auth->isAssigned($role->getName(), $model->getId()));?></td>
                </tr>
                <?php endforeach;?>
            </tbody>                
        </table>
        <div>
            <?php echo CHtml::submitButton('Save');?>
        </div>
        <?php echo CHtml::endForm();?>
    </div>
</div>